<template>
  <el-dialog
    :title="title"
    :visible.sync="innerVisible"
    width="600px"
    @close="handleCancel"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="180px"
    >
      <el-form-item label="年度">
        <!-- <el-select
          placeholder="请选择"
          v-model="form.year"
          clearable
          :disabled="isDetail"
        >
          <el-option
            v-for="item in yearList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select> -->
        <el-date-picker
          v-model="form.year"
          type="year"
          placeholder="请选择"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="科研团队个数">
        <el-input
          v-model="form.groupCount"
          placeholder="请输入"
          :disabled="isDetail"
          type="number"
        />
      </el-form-item>

      <el-form-item label="聚集科研人才人数">
        <el-input
          v-model="form.researchPeopleCount"
          placeholder="请输入"
          :disabled="isDetail"
          type="number"
        />
      </el-form-item>

      <el-form-item label="在校师生人数">
        <el-input
          v-model="form.schoolPeopleCount"
          placeholder="请输入"
          :disabled="isDetail"
          type="number"
        />
      </el-form-item>

      <el-form-item label="备注">
        <el-input
          v-model="form.notes"
          placeholder="请输入"
          :disabled="isDetail"
          type="textarea"
          :rows="3"
        />
      </el-form-item>
    </el-form>

    <div
      slot="footer"
      class="dialog-footer"
      v-if="!isDetail"
    >
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import {
  industryPlatTypeOptions,
  constructionStatusOptions
} from '@/utils/project/data'
import {
  civilTypeOptions,
  scienceFieldOptions
} from '@/utils/project/data'
import dayjs from 'dayjs'

export default {
  name: 'ProgressDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '填写信息'
    },
    isDetail: {
      type: Boolean
    },
    currentData: {
      type: Object
    }
  },
  data() {
    return {
      form: {
        pkid: '',
        year: '',
        researchPeopleCount: '',
        schoolPeopleCount: '',
        groupCount: '',
        notes: ''
      },
      rules: {
        // 表单校验规则 (如果需要)
      },
      innerVisible: false,
      yearList: ['2025', '2024']
    }
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
    innerVisible(val) {
      this.$emit('update:visible', val)
    },
    currentData(val) {
      this.form = val
      this.form.year = val.year.toString()
      console.log(this.form.year, 'this.form.year')
    }
  },
  computed: {
    industryPlatTypeOptions() {
      return industryPlatTypeOptions
    },
    constructionStatusOptions() {
      return constructionStatusOptions
    },
    civilTypeOptions() {
      return civilTypeOptions
    },
    scienceFieldOptions() {
      return scienceFieldOptions
    }
  },
  methods: {
    handleCancel() {
      this.$emit('update:visible', false)
    },
    handleConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.$emit('confirm', { ...this.form })
          this.handleCancel()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/dialog.scss';
::v-deep .el-input__inner {
  width: 320px !important;
}
::v-deep .el-textarea__inner {
  width: 320px !important;
}
</style>
